package com.wkr.tool;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.core.MessageCreator;

import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.Session;

public class sender {

    @Autowired
    @Qualifier("jmsTemplate")
    private JmsTemplate jmsQueueTemplate;

    private Logger logger = LoggerFactory.getLogger(sender.class);
    //发送消息
    public String sendMessage(final String message) {
        logger.info("消息内容："+message);
        jmsQueueTemplate.send(new MessageCreator() {
            @Override
            public Message createMessage(Session session) throws JMSException {
                return session.createTextMessage(message);
            }
        });
        return "O^O";
    }
}
